package org.misalen.web.server.controllers.driver;

import java.util.HashMap;
import java.util.List;

import org.misalen.annotations.ControllerApi;
import org.misalen.annotations.InterfaceApi;
import org.misalen.web.database.model.mysql.sys.SysWordbookItem;
import org.misalen.web.server.config.ServerResult;
import org.misalen.web.server.config.ServerUrl;
import org.misalen.web.server.controllers.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ControllerApi(value = "通用基础接口", description = "客户端配置", index = 000)
@RequestMapping(value = ServerUrl.DriverBasisControllerUrl)
public class DriverBasisController extends BaseController {

	@RequestMapping(value = "/config", method = { RequestMethod.POST, RequestMethod.GET })
	@InterfaceApi(value = "初始化配置(返回一些枚举信息,展示用itemName,与后台交互用itemCode)", resultClass = { SysWordbookItem.class })
	public @ResponseBody ServerResult config() {
		List<SysWordbookItem> proSocialGroups = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("pro-social-groups").getPrimaryKey());
		List<SysWordbookItem> proAge = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("pro-age").getPrimaryKey());
		List<SysWordbookItem> proExtractType = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("pro-extract-type").getPrimaryKey());
		List<SysWordbookItem> proExtractState = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("pro-extract-state").getPrimaryKey());
		List<SysWordbookItem> proCity = sysWordbookItemRepository
				.findByWbId(sysWordbookRepository.getByCode("pro-city").getPrimaryKey());
		for (int i = 0; i < proCity.size(); i++) {
			if (proCity.get(i).getItemCode().equals("全国")) {
				proCity.remove(i);
				break;
			}
		}
		HashMap<String, List<SysWordbookItem>> hashMap = new HashMap<String, List<SysWordbookItem>>();
		hashMap.put("pro-extract-type", proExtractType);
		hashMap.put("pro-extract-state", proExtractState);
		hashMap.put("pro-social-groups", proSocialGroups);
		hashMap.put("pro-age", proAge);
		hashMap.put("pro-city", proCity);
		return ServerResult.ok(hashMap);
	}

}
